﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SHDQGSWEB.Models
{
    public class ProductRepository
    {
        SHDQGSDBDataContext db = new SHDQGSDBDataContext();
        public IQueryable<Product> FindAllProducts()
        {
            return from product in db.Products
                   select product;
        }
        public Product FindProduct(int productId)
        {
            return db.Products.Single(p => p.ProductId == productId);
        }
        public IQueryable<Product> FindModedProducts(string mode)
        {
            return from product in db.Products
                   where product.DisplayMode == mode
                   select product;
        }
        public bool Add(Product product)
        {
            try
            {
                db.Products.InsertOnSubmit(product);
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
        public bool Delete(Product product)
        {
            try
            {
                db.Products.DeleteOnSubmit(product);
                
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
        public bool Save()
        {
            try
            {
                this.db.SubmitChanges();
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
    }
}